﻿//示例一
class Date
{
public:
	// 不是默认构造函数
	Date(int year, int month = 1, int day = 1)
	{
		_year = year;
		_month = month;
		_day = day;
	}
private:
	int _year;
	int _month;
	int _day;
};

class DateSet
{
public:
	DateSet(int& b)
		:_d1(2024,2,5)
		,_d2(2025,1,1)
		,_i(5)
		,_b(b)
	{

	}
private:
	Date _d1;
	Date _d2;
	const int _i;
	int& _b;
};

int main()
{
	int b = 5;
	DateSet date(b);
	return 0;
}


//示例二
#include<stdlib.h>
class Date
{
public:
	Date(int year = 1, int month = 1, int day = 1)
	{
		_year = year;
		_month = month;
		_day = day;
	}
private:
	int _year;
	int _month;
	int _day;
};

class DateSet
{
public:
	DateSet()
		:_d1(2024, 2, 5)
		, _a2(100)
	{

	}
private:
	// 注意这⾥不是初始化，这⾥给的是缺省值，这个缺省值是给初始化列表的
	// 如果初始化列表没有显⽰初始化，默认就会⽤这个缺省值初始化
	Date _d1 = (2008, 1, 1);
	Date _d2 = (2008, 1, 1);

	int _a1 = 1;
	int _a2 = 1;
	int _a3 = 1;
	int* _ptr = (int*)malloc(12);
};

int main()
{
	DateSet date;
	return 0;
}


//示例三
class Date
{
public:
	//全缺省构造函数属于默认构造函数
	Date(int year = 1, int month = 1, int day = 1)
	{
		_year = year;
		_month = month;
		_day = day;
	}
private:
	int _year;
	int _month;
	int _day;
};

class DateSet
{
public:
	DateSet()
	{
		_i = 5;
	}
private:
	Date _d1;
	Date _d2;
	int _i;
	int _j;
};

int main()
{
	DateSet date;
	return 0;
}



